#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
const int B = 710;
int H[N];
int fath[N];
vector<int> bian[N];
int f[20][N];
int dep[N];
void dfs(int x,int fa){
    dep[x] = dep[fa] + 1;
    f[0][x] = fa;
    for(int i = 1;(1<<i) <= dep[x];i++){
        f[i][x] = f[i - 1][f[i - 1][x]];
    }
    for(int v : bian[x]){
        dfs(v,x);
    }
}
int lca(int x,int y){
    if(dep[x] < dep[y]){
        swap(x,y);
    }
    for(int i = 19;i >= 0;i--){
        if(dep[f[i][x]] >= dep[y]){
            x = f[i][x];
        }
    }
    if(x == y){
        return x;
    }
    for(int i = 19; i>= 0;i--){
        if(f[i][x] != f[i][y]){
            x = f[i][x];
            y = f[i][y];
        }
    }
    return x;
}
int main(){
    int n;
    cin>>n;
    int r,q;
    cin>>r>>q;
    cin>>H[1];
    for(int i = 2;i<=n;i++){
        cin>>fath[i]>>H[i];
    }
    dfs(1,0);
    vector<int> rdp;
    
}